#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
string ed;
queue<string> q;
map<string, string> mp;

void moveA(string x) {
	string y = x;
	for (int i = 0; i < 4; i++) swap(x[i], x[7 - i]);
	if (mp.count(x) == 0) {
		q.push(x);
		mp[x] = mp[y] + 'A';
	}
}

void moveB(string x) {
	string y = x;
	x[0] = y[3], x[1] = y[0], x[2] = y[1], x[3] = y[2],
	x[4] = y[5], x[5] = y[6], x[6] = y[7], x[7] = y[4];
	if (mp.count(x) == 0) {
		q.push(x);
		mp[x] = mp[y] + 'B';
	}
}

void moveC(string x) {
	string y = x;
	x[1] = y[6], x[2] = y[1], x[5] = y[2], x[6] = y[5];
	if (mp.count(x) == 0) {
		q.push(x);
		mp[x] = mp[y] + 'C';
	}
}

void bfs() {
	q.push("12345678"); mp["12345678"] = "";
	while (q.size()) {
		string s = q.front(); q.pop();
		moveA(s);
		moveB(s);
		moveC(s);
		if (mp.count(ed)) {
			cout << mp[ed].size() << endl << mp[ed] << endl;
			return;
		}
	}
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	char c;
	for (int i = 0; i < 8; i++) {
		cin >> c;
		ed += c;
	}
	bfs();
	return 0;
}